package com.sparrow.source.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author yanghao🕷
 * @date 2021/7/12
 **/
@Configuration
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //核心线程大小
        executor.setCorePoolSize(5);
        //最大线程大小
        executor.setMaxPoolSize(20);
        //队列最大容量
        executor.setQueueCapacity(100);
        //存活时间
        executor.setKeepAliveSeconds(3000);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
}
